package com.itheima.web.controller.ums;

import com.itheima.result.ResultData;
import com.itheima.service.ums.UmsMenuService;
import com.itheima.vo.ums.UmsMenu;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("menu")
public class UmsMenuController {
    @DubboReference
    private UmsMenuService umsMenuService;
    @PostMapping("create")
    public ResultData create(@RequestBody UmsMenu umsMenu){
        umsMenuService.insert(umsMenu);
        return ResultData.ok("操作成功","");
    }
    @PostMapping("delete/{id}")
    public ResultData delete(@PathVariable Integer id){
        umsMenuService.removeById(id);
        return ResultData.ok("操作成功","");
    }
    @GetMapping("list/{parentId}")
    public ResultData list(@PathVariable Integer parentId ,Integer pageNum,Integer pageSize){
        return umsMenuService.listParentId(parentId,pageNum,pageSize);
    }
    @GetMapping("treeList")
    public ResultData treeList(){
        return umsMenuService.treeList();
    }
    @PostMapping("update/{id}")
    public ResultData update(@PathVariable Integer id,@RequestBody UmsMenu umsMenu){
        umsMenu.setId(id);
        umsMenuService.updateById(umsMenu);
        return ResultData.ok("操作成功",1);
    }
    @PostMapping("updateHidden/{id}")
    public ResultData updateHidden(@PathVariable Integer id,Integer hidden){
        umsMenuService.updateHidden(id,hidden);
        return ResultData.ok("操作成功","");
    }
    @GetMapping("{id}")
    public ResultData getById(@PathVariable Integer id){
        return ResultData.ok("操作成功",umsMenuService.getById(id));
    }
}
